home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / MPW Goodies / MPW Goodies⁄DTS / CheckWindowOut < prev    next >
Text File  |  2022-08-05  |  4KB  |  168 lines

  1. #    CheckWindowOut - check a window out for modification
  2. #
  3. #    Usage:    CheckWindowOut window
  4. #
  5. #    Status:    CheckWindowOut may return the following status values:
  6. #
  7. #            0        the window was checked out
  8. #            1        error
  9. #            4        the user canceled
  10. #
  11. #    CheckWindowOut uses the ProjectInfo command to determine the
  12. #    parent project for a file open as a window. Once this project
  13. #    has been determined, the file can be properly checked out.
  14. #    A dialog allows the user to type in a short comment that
  15. #    indicates what the reason for checking the file out was.
  16. #    This will be logged into the project, and, if the file has
  17. #    a LastChange marker, will be logged into the file.
  18. #
  19. #    © 1988, 1989 Apple Computer, Inc.
  20. #    All rights reserved.
  21.  
  22. Set Exit 0
  23.  
  24. # the following helps to debug until MPW sends echos to Dev:Console instead of Dev:StdErr
  25. If {Echo} == 1
  26.     Set somewhere "∑∑ '{Worksheet}∂'"
  27. Else
  28.     Set somewhere '∑ Dev:Null'
  29. End
  30.  
  31. Begin
  32.  
  33.     Set Comment "{SystemFolder}Comment"    # file to compose comment in
  34.     Set Window "{1}"
  35.  
  36.     # get short name of window
  37.  
  38.     If "{Window}" !~ /:*([¬:]+:*)*([¬:]+)®1/
  39.         Exit 1
  40.     End
  41.     Set Short "{®1}"                    # get short name for dialogs
  42.     Set Cant "“{Short}” can’t be checked out "
  43.  
  44.     # check what project the window belongs to
  45.  
  46.     Set Info "`ProjectInfo "{Window}"`"
  47. ###    If "{Info}" !~ /≈Project: (≈∫)®1 ≈/
  48.     If "{Info}" !~ /≈Project: (≈)®1     Checked out: ≈/
  49.         Alert "{Cant}because it doesn’t belong to a project."
  50.         Exit 1
  51.     End
  52.     Set Project "{®1}"
  53.  
  54.     # check if the window is already checked out
  55.  
  56.     If "{Info}" =~ /[¬,]+,[¬ ∂t]+∂+≈/
  57.         Alert "{Cant}again because it’s already checked out for modification."
  58.         Exit 1
  59.     End
  60.  
  61.     # check if the window is ModifyReadOnly'd
  62.  
  63.     If "{Info}" =~ /[¬,]+,[¬ ∂t]+∂*≈/
  64.         Alert "{Cant}because it’s a modified read-only copy."
  65.         Exit 1
  66.     End
  67.  
  68.     # get the version that is checked out
  69.  
  70.     If "{Info}" !~ /[¬,]+,([0-9]+)®1≈/
  71.         Exit 1
  72.     End
  73.     Set OldVersion {®1}
  74.  
  75.     # check if the project is mounted
  76.  
  77.     ProjectInfo -project "{Project}" -only ∑ Dev:Null
  78.     If {Status} != 0
  79.         Alert "{Cant}because the project “{Project}” is not mounted."
  80.         Exit 1
  81.     End
  82.  
  83.     # see if the file is already checked out
  84.  
  85.     Set Info "`ProjectInfo -latest -project "{Project}" "{Short}"`"
  86.     If "{Info}" == ""
  87.         Alert "{Cant}because it isn’t really in the project “{Project}”."
  88.         Exit 1
  89.     Else If "{Info}" =~ /≈r: (?*[¬ ])®1 +Checked out≈/
  90.         Set Owner "{®1}"
  91.         If "{Owner}" == "{User}"
  92.             Alert "{Cant}because you have already checked it out elsewhere."
  93.             Exit 1
  94.         Else
  95.             Alert "{Cant}because it has already been checked out by {Owner}."
  96.             Exit 1
  97.         End
  98.     End
  99.  
  100.     # get position within window so we can return to it later
  101.  
  102.     If `Position -c "{Window}"` !~ /([0-9]+)®1,([0-9]+)®2/
  103.         Exit 1
  104.     End
  105.     Set SelectionStart {®1}
  106.     Set SelectionSize `Evaluate {®2}-{®1}`
  107.  
  108.     # get a comment about the change
  109.  
  110.     Set IgnoreCmdPeriod 1
  111.     Echo -n "{DefaultComment}" | CoolRequest -d -q "What are you are going to change in “{Short}”?" >"{Comment}"
  112.     Set CommentStatus {Status}
  113.     Set IgnoreCmdPeriod 0
  114.     If {CommentStatus} != 0
  115.         Delete -i "{Comment}"
  116.         If {CommentStatus} == 4
  117.             Exit 4
  118.         End
  119.         Exit 1
  120.     End
  121.  
  122.     # check the file out
  123.  
  124.     # *** what about introducing a new branch?
  125.     # *** what about entering a "task"?
  126. ###    CheckOut -cf "{Comment}" -m "{Window}" || Set CheckOutStatus {Status}
  127.     CheckOut -cf "{Comment}" -m -project "{Project}" "{Window}" || Set CheckOutStatus {Status}
  128.     If {CheckOutStatus} != 0
  129.         Delete -i "{Comment}"
  130.         # *** need to check this more closely (Cancel from dialog gets here)
  131.         Alert "I confused:   CheckOut failed!"
  132.     End
  133.  
  134.     Find •!{SelectionStart}:§!{SelectionSize} "{Window}"
  135.  
  136.     If {ProjectHeaders}
  137.         Mark -y § OldSelection "{Window}"
  138.  
  139.         # *** what should we do if there is no marker?
  140.         # *** we can create a header, or not put the change in the file at all
  141.         AddChange "{Window}" "{Comment}"
  142.  
  143.         Find OldSelection "{Window}"
  144.         Unmark OldSelection "{Window}"
  145.  
  146.         Save "{Window}"
  147.     End
  148.  
  149.     Delete -i "{Comment}"
  150.  
  151.     # check if the version is too new
  152.  
  153.     Set Info "`ProjectInfo "{Window}"`"
  154.     If "{Info}" !~ /[¬,]+,([0-9]+)®1≈/
  155.         Exit 1
  156.     End
  157.     Set NewVersion {®1}
  158.     Set Increment `Evaluate {NewVersion} - {OldVersion}`
  159.     If {Increment} > 0
  160.         If {Increment} == 1
  161.             Alert "The “{Short}” that you just checked out is a version newer than your old copy."
  162.         Else
  163.             Alert "The “{Short}” that you just checked out is {Increment} versions newer than your old copy."
  164.         End
  165.     End
  166.  
  167. End {somewhere}
  168.